package com.cloud.code.md5;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

/**
 * 模拟用户登录，密码比对
 */
public class Md5Test {

    public static void main(String[] args) throws NoSuchAlgorithmException {
        String password = "adminw123";
        String passwordbd = "AZICOnu9cyUFFvBp3xi1AA==";

        System.out.println(passwordbd.equalsIgnoreCase(md5(password)));

        System.out.println(md5(password));
    }

    public static String md5(String password) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        return Base64.getEncoder().encodeToString(md5.digest(password.getBytes(StandardCharsets.UTF_8)));
    }
}
